package com.sh.粘包半粘包.one;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException, InterruptedException {
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("服务器启动，等待连接...");
        Socket socket = serverSocket.accept();
        System.out.println("客户端连接成功");

        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();

        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = inputStream.read(buffer))!= -1) {
            System.out.println("接收到的数据：" + new String(buffer, 0, bytesRead));
        }

        Thread.sleep(1000000000);
//        socket.close();
//        serverSocket.close();
    }
}